package org.cresource.user.conteoller;


import org.cresource.basic.util.AjaxResult;
import org.cresource.user.domain.LoginDto;
import org.cresource.user.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 登录
 */
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
   private ILoginService loginService;

   //前后端登录 接收登录数据 返回ajax
    @PostMapping("/account")
    public AjaxResult account(@RequestBody LoginDto loginDto){
        try {
            return   loginService.account(loginDto);
        } catch (Exception e) {
            System.out.println(e);
            return AjaxResult.me().setMessage("登录c 系统错误");
        }
    }



    //第三方登录 回调页面
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody Map<String,String> map){
        try {
            System.out.println(map);
            return   loginService.wechat(map);
        } catch (Exception e) {
            System.out.println(e);
            return AjaxResult.me().setMessage("登录c 系统错误");
        }
    }

     //绑定授权
     @PostMapping("/binder/wechat")
     public AjaxResult binder(@RequestBody Map<String,String> map){
         try {
             System.out.println(map);
             return   loginService.binder(map);
         } catch (Exception e) {
             System.out.println(e);
             return AjaxResult.me().setMessage("登录c 系统错误");
         }
     }



}

